package com.iscas.tech.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iscas.tech.entity.AtNewsattach;
import com.iscas.tech.mapper.AtNewsattachMapper;
import com.iscas.tech.param.AtNewsattachPageParam;
import com.iscas.tech.service.AtNewsattachService;
import com.iscas.tech.vo.AtNewsattachQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.pagination.PageUtil;
import io.geekidea.springbootplus.framework.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 新闻附件表 服务实现类
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@Service
public class AtNewsattachServiceImpl extends BaseServiceImpl<AtNewsattachMapper, AtNewsattach> implements AtNewsattachService {

    @Autowired
    private AtNewsattachMapper atNewsattachMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAtNewsattach(AtNewsattach atNewsattach) throws Exception {
        return super.save(atNewsattach);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAtNewsattach(AtNewsattach atNewsattach) throws Exception {
        return super.updateById(atNewsattach);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAtNewsattach(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AtNewsattachQueryVo> getAtNewsattachPageList(AtNewsattachPageParam atNewsattachPageParam) throws Exception {
        Page page = PageUtil.getPage(atNewsattachPageParam, OrderItem.desc(getLambdaColumn(AtNewsattach::getCreatetime)));
        IPage<AtNewsattachQueryVo> iPage = atNewsattachMapper.getAtNewsattachPageList(page, atNewsattachPageParam);
        return new Paging(iPage);
    }

    @Override
    public boolean deleteByNewsId(Integer id) throws Exception {
        return atNewsattachMapper.deleteByNewsId(id);
    }

}
